package org.gientech.learnsen.job;

import org.gientech.learnsen.service.StreamProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

@Service
public class ScheduleJob {
    @Autowired
    private StreamProducer streamProducer;

    @PostConstruct
    public void generateBook() {
         Executors.newSingleThreadScheduledExecutor()
                 .scheduleAtFixedRate(() -> streamProducer.sendRecord("bookKey"),
                         0, 5, TimeUnit.SECONDS);
     }

}
